<template>
  <div id="hotel-policy">
    <div class="warpper">
      <el-form label-width="80px">
        <el-form-item label="入住时间">
          <!-- <el-input v-model="form.checkInTime" placeholder="请输入入住时间"></el-input> -->
          <el-time-picker v-model="form.checkInTime"  placeholder="请输入入住时间" format="HH:mm:ss" value-format="HH:mm:ss">
          </el-time-picker>
        </el-form-item>
        <el-form-item label="离店时间">
            <el-time-picker v-model="form.checkOutTime" 
             placeholder="请输入离店时间" format="HH:mm:ss" 
             value-format="HH:mm:ss"
             :picker-options="{
             minTime: form.checkInTime
            }">
          </el-time-picker>
        </el-form-item>
        <el-form-item label="儿童政策">
          <el-input type="textarea" :rows="5" v-model="form.childrenRule" placeholder="请输入儿童政策"></el-input>
        </el-form-item>
        <el-form-item label="宠物">
          <el-input type="textarea" :rows="5" v-model="form.petRule" placeholder="请输入宠物政策"></el-input>
        </el-form-item>
        <el-form-item label="接受信用卡">
          <el-input type="textarea" :rows="5" v-model="form.acceptBankCard" placeholder="请输入信用卡政策"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="information-btn">
      <el-form-item>
        <el-button type="primary" @click="next" v-if="isCreate">下一步</el-button>
        <el-button type="primary" @click="back" v-if="isCreate">返回</el-button>
        <el-button type="primary" @click="next" v-if="!isCreate">保存</el-button>
        <el-button @click="back" v-if="!isCreate">关闭</el-button>
      </el-form-item>
    </div>
  </div>
</template>
<script>
import { updateRule } from '@/public/js/hotelInfomation'
export default {
  props: ['datas'],
  name: 'HotelFacilities',
  data () {
    return {
      isCreate: true
    }
  },
  computed: {
    form () {
      return this.datas[0]
    }
  },
  created () {
    this.isCreate = JSON.parse(sessionStorage.getItem('isCreate'))
    sessionStorage.removeItem('last')
  },
  methods: {
    next () {
      let data = {
        'timestamp': 0,
        'version': 'string',
        'operation': 'string',
        'hotelId': sessionStorage.getItem('hotelId'),
        'checkInTime': this.datas[0].checkInTime,
        'checkOutTime': this.datas[0].checkOutTime,
        'childrenRule': this.datas[0].childrenRule,
        'petRule': this.datas[0].petRule,
        'acceptBankCard': this.datas[0].acceptBankCard
      }
      updateRule(data).then(res => {
        if (!res.data.errCode) {
          if (this.isCreate) {
            // 切换tab
            this.$emit('input', 'fourth')
          } else {
            this.$message.success('修改成功')
          }
        }
      })
    },
    back () {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="scss">
.hotel-policy {
  .warpper {
    width: 50%;
    padding: 20px;
    .el-form-item {
      margin-bottom: 20px;
    }
  }
}
</style>
